package com.deng.api.dto;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.*;
import com.deng.api.entity.SysMenu;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;


@Getter
@Setter
public class MenuDTO implements Serializable {

    private static final long serialVersionUID = 100006L;

    @ApiModelProperty("ID")
    private Long id;

    @ApiModelProperty("上级菜单ID")
    private Long pid;

    @ApiModelProperty("子菜单数目")
    private Integer subCount;

    @ApiModelProperty("菜单类型")
    private Integer type;

    @ApiModelProperty("菜单标题")
    private String title;

    @ApiModelProperty("组件名称")
    private String name;

    @ApiModelProperty("组件")
    private String component;

    @ApiModelProperty("排序")
    private Integer menuSort;

    @ApiModelProperty("图标")
    private String icon;

    @ApiModelProperty("链接地址")
    private String path;

    @ApiModelProperty("是否外链,外部链接http://www.baidu.com")
    private Boolean iframe;

    @ApiModelProperty("是否缓存")
    private Boolean cache;

    @ApiModelProperty("隐藏")
    private Boolean hidden;

    @ApiModelProperty("权限")
    private String permission;

    @ApiModelProperty("子集菜单列表")
    private List<MenuDTO> children;

    /**
     * 是否有子菜单
     *
     * @return
     */
    public Boolean getHasChildren() {
        return subCount > 0;
    }

    /**
     * 前端组件显示的el-tree内容
     */
    public String getLabel() {
        return title;
    }

    /**
     * 是否是叶子（没有子菜单就是叶子）
     *
     * @return
     */
    public Boolean getLeaf() {
        return subCount <= 0;
    }

    /**
     * menu转化为dto
     * @param menu
     * @return
     */
    public static MenuDTO toDTO(SysMenu menu) {
        MenuDTO dto = new MenuDTO();
        //表示把相同属性的实体进行copy
        BeanUtil.copyProperties(menu, dto);
        return dto;
    }

}
